package com.linjacy.container.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linjacy.common.utils.PageUtils;
import com.linjacy.common.utils.Query;
import com.linjacy.container.product.dao.TransporterDao;
import com.linjacy.container.product.entity.StandardEntity;
import com.linjacy.container.product.entity.TransporterEntity;
import com.linjacy.container.product.service.TransporterService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("transporterService")
public class TransporterServiceImpl extends ServiceImpl<TransporterDao, TransporterEntity> implements TransporterService {
    @Autowired
    private TransporterDao transporterDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<TransporterEntity> wrapper=new QueryWrapper<>();
        String transporterName = (String) params.get("transporterName");
        if(!StringUtils.isEmpty(transporterName)){
            wrapper.like("transporter_name",transporterName);
        }
        IPage<TransporterEntity> page = this.page(
                new Query<TransporterEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void saveTransporter(TransporterEntity transporterEntity) {
        baseMapper.insert(transporterEntity);
    }

    @Override
    public int deleteById(TransporterEntity transporterEntity) {
        int status = transporterDao.selectCountById(transporterEntity.getTransporterId());
        if(status==1){
            return 0;
        }else{
            int i = baseMapper.deleteById(transporterEntity.getTransporterId());
            return i;
        }
    }
}
